package Pattern.AdapterPattern.program7;

public class ChinesePostalCode {
    private boolean digitFlag = true;
    public boolean isValidChinesePcode(String postalCode, String province) {

        char[] pCode = toNonBlankCharArray(postalCode);

        if (pCode.length != 6)
            return false;

        for (int i = 0; i < pCode.length / 2; i++) {
            /*if (Character.isLetter(pCode[2 * i]) == false)
                characterFlag = false;
            if (Character.isDigit(pCode[2 * i + 1]) == false)
                digitFlag = false;*/
            if(Character.isDigit(pCode[2*i])==false){
                digitFlag = false;
            }
        }

        if ((digitFlag == false))
            return false;
        else
            return true;
    }

    public char[] toNonBlankCharArray(String postalCode) {
        int m = 0;

        for (int k = 0; k < postalCode.length(); k++) {
            if (Character.isSpaceChar(postalCode.charAt(k)) == false) {
                m++;
            }
        }

        char[] p = new char[m];

        int n = 0;
        for (int k = 0; k < postalCode.length(); k++) {
            if (Character.isSpaceChar(postalCode.charAt(k)) == false) {
                p[n] = postalCode.charAt(k);
                n++;
            }
        }
        return p;
    }
}
